<#import "../tpl/pageTep.ftl" as page>
<@page.pageBase currentMenu="返利明细">
<style>
    .form-horizontal .controls {
        line-height: 40px;
        height: 40px;
    }

    .form-horizontal .time-label {
        width: 80px;
    }

    .form-panel .time-input {
        width: 70px;
    }

    .span5 {
        width: 186px;
    }

    .form-horizontal .money-label {
        line-height: 40px;
        width: 140px;
    }

    .money-span5 {
        width: 166px;
    }

    .money-p p {
        margin: 0 0 0 10px;
        padding: 0;
        height: 24px;
        line-height: 24px;
        font-size: 12px
    }

    .money-p div {
        float: left;
    }

    .money-p span {
        color: #6cb5f4;
    }

    .form-horizontal .rate-label {
        width: 120px;
    }

    .button-primary {
        margin-left: 5px;
    }

    .money-p {
        border-bottom: 1px solid #dfdfdf;
        height: 55px !important;
        line-height: 55px !important;
    }

    .form-horizontal .time-label {
        width: 80px;
        line-height: 40px;
    }

</style>
<form id="searchForm" class="form-panel">
    <ul class="panel-content">
        <li class="money-p">
            <div class="form-actions span12">
                <label class="time-label control-label">总返利金额：</label>
                <div class="controls">
                    <input type="text" class="time-input input-normal" id="amountInput" disabled value="0"/>
                </div>
                <label class="money-label control-label">爱优享平台已获得金额：</label>

                <div class="controls">
                    <input type="text" class="time-input input-normal" id="sumInput" value="0" disabled/>
                </div>

            </div>
            <div class="rebateInformation">
            </div>
            <a class="query-button button button-primary" href="javascript:add()" style="margin-left: 10px">
                设置
            </a>
        </li>
        <li>
            <div class="control-group span5">
                <div class="search-controls  controls">
                    <input type="text" name="orderID" id="title" value="" placeholder="搜索关键字">
                </div>
            </div>
            <div class="form-actions span2">
                <button type="submit" class="button  button-primary">
                    搜索
                </button>
            </div>

        </li>
    </ul>
</form>
<div id="grid"></div>
<#------------------------------------------------------添加表单start------------------------------------------------------->
<div id="editContent" style="display:none;">
    <form id="editForm" class="form-horizontal" action="${basepath}/manage/systemSetting/updateJson" method="post">
        <input type="hidden" class="input-normal control-text" name="id" value="1"/>

        <div class="row">
            <div class="control-group span16">
                <label class="rate-label control-label">佣金占比润：</label>

                <div class="controls">
                    <input type="text" class="input-normal control-text" name="percent" data-rules="{required : true}">%
                </div>
            </div>
            <div class="control-group span16">
                <label class="rate-label control-label">A级获得佣金占比：</label>

                <div class="controls">
                    <input type="text" class="input-normal control-text" name="aPercent">%
                </div>
            </div>
            <div class="control-group span16">
                <label class="rate-label control-label">B级获得佣金占比：</label>

                <div class="controls">
                    <input type="text" class="input-normal control-text" name="bPercent">%
                </div>
            </div>
            <div class="control-group span16">
                <label class="rate-label control-label">C级获得佣金占比：</label>

                <div class="controls">
                    <input type="text" class="input-normal control-text" name="cPercent">%
                </div>
            </div>
            <div class="control-group span16">
                <label class="rate-label  control-label">志愿者获得佣金占比：</label>

                <div class="controls">
                    <input type="text" class="input-normal control-text" name="dPercent">%
                </div>
            </div>
        </div>
    </form>
</div>
<#------------------------------------------------------添加表单end------------------------------------------------------->
<script>
    /*-------------------------------------------------------- 表格数据渲染start-----------------------------------*/
    var Grid = BUI.Grid,
            Store = BUI.Data.Store,
            columns = [
                {title: '序号', dataIndex: 'id', elCls: 'center', width: '15%'},
                {title: '获利者', dataIndex: 'affName', elCls: 'center', width: '18%'},
                {title: '下单日期', dataIndex: 'createTime', elCls: 'center', width: '18%'},
                {title: '下单人', dataIndex: 'accName', elCls: 'center', width: '18%'},
                {title: '订单号', dataIndex: 'orderID', elCls: 'center', width: '18%'},
                {title: '获得返利金额', dataIndex: 'money', elCls: 'center', width: '18%'}
            ];
    var store = new Store({
                url: '${basepath}/manage/brokerage/loadData',
                autoLoad: true, //自动加载数据
                params: { //配置初始请求的参数
                    length: '10',
                    status: $("#phone").val()
                },
                pageSize: 10,	// 配置分页数目
                root: 'list',
                totalProperty: 'total'
            }),
            grid = new Grid.Grid({
                render: '#grid',
                columns: columns,
                loadMask: true, //加载数据时显示屏蔽层
                store: store,
                plugins: [Grid.Plugins.CheckSelection], // 插件形式引入多选表格

                // 底部工具栏
                bbar: {
                    pagingBar: true
                }
            });
    grid.render();

    var form = new BUI.Form.HForm({
        srcNode: '#searchForm'
    }).render();

    form.on('beforesubmit', function (ev) {
        //序列化成对象
        var obj = form.serializeToObject();
        obj.start = 0; //返回第一页
        store.load(obj);
        return false;
    });

    /*-------------------------------------------------------- 表格数据渲染end-----------------------------------*/
    /*----------------------------------------------添加表单处理 begin------------------------------------*/
    var Select = BUI.Select, Data = BUI.Data;
    var editForm = new BUI.Form.Form({
        srcNode: '#editForm',
        submitType: 'ajax',
        callback: function (data) {
            window.location.href = "${basepath}/manage/wallet/toList"
        }
    }).render();

    var editDialog = new BUI.Overlay.Dialog({
        title: '佣金设置',
        width: 400,
        height: 350,
        contentId: 'editContent',
        success: function () {
            editForm.ajaxSubmit();
        }
    });
    //添加按钮事件
    function add() {
        editDialog.show();
    }
    /*----------------------------------------------编辑表单处理 end------------------------------------*/

    //查询爱心钱包总数
    function queryInput() {
        $.ajax({//查询爱心钱包总数
            type: "GET",
            url: "/manage/brokerage/selectSum",
            dataType: "json",
            success: function (data) {
                var walletMoney = data.data;
                $("#amountInput").val(walletMoney);
            }
        })
    }
    queryInput();
    //查询爱优享返利金额
    $.ajax({
        type: 'GET',
        url: "/manage/brokerage/selectAdminSum",
        dataType: "json",
        success: function (data) {
            var sum = data.data;
            $("#sumInput").val(sum);
        }
    });
    //查询返利比例
    $.ajax({
        type: "GET",
        url: "/manage/systemSetting/selectDetail",
        dataType: "json",
        data: {
            id: 1
        },
        success: function (data) {
            var list = data.data;
            var listHtml = '';
            listHtml += '<p>返利分配比例：商品利润的<span>' + list.percent + '</span>%作为返利。</p>' +
                    '<p>返利分配比例：A级机构<span>' + list.aPercent + '</span> %，B级机构<span>' + list.bPercent + '</span> %，' +
                    'C级机构<span>' + list.cPercent + '</span> %，志愿者<span>' + list.dPercent + '</span>%</p>';
            $(".rebateInformation").html(listHtml);
        }
    })
</script>

</@page.pageBase>